/**
 * Copyright (C) 2010 D. Zoller, M. Richter, M. Blumenstein & W. Biller
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.siafu.rest.commands.parser.util;

import com.googlecode.siafu.rest.model.Position;

/**
 * @author D. Zoller
 * @version $Id: SiafuResultParserHelper.java,v 1.3 2010-06-14 07:57:57 nosebrain Exp $
 */
public class SiafuResultParserHelper {
	
	/**
	 * the regex to split siafu strings in key and value
	 */
	public static final String KEY_VALUE_REGEX = "\\/";
	
	/**
	 * parses the string to a {@link Position} object
	 * @param string
	 * @return the parsed position
	 */
	public static Position parsePosition(String string) {
		if (string == null) {
			throw new IllegalArgumentException("The string is null.");
		}
		
		String[] positiondata = string.split("#");
		return new Position(Double.parseDouble(positiondata[0]), Double.parseDouble(positiondata[1]));
	}
	
	/**
	 * @param string
	 * @return the value of the siafu string
	 */
	public static String getValue(final String string) {
		final String value = string.split(KEY_VALUE_REGEX)[1];
		return value.substring(value.indexOf(":") + 1);
	}
	
	/**
	 * @see SiafuResultParserHelper#getValue(String)
	 * @param string
	 * @return the boolean value of the siafu string
	 */
	public static boolean getBooleanValue(final String string) {
		return new Boolean(getValue(string));
	}
}
